<template>
  <view>
    <!-- 吸顶搜索 -->
    <view class="search">
      <my-search @click.native="gotoSearch"></my-search>
    </view>
    <!-- 轮播图区域 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="(item,i) in list" :key="i">
        <navigator class="swiper-item" :url="'/subpackages/goods_detail/goods_detail?goods_id='+ item.goods_id">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 分类导航区域 -->
    <view class="nav-list">
      <view @click="navClickHanlder(item)" class="nav-item" v-for="(item,i) in navList" :key="i">
        <image :src="item.image_src" ></image>
      </view>
    </view>
    <!-- 楼层区域 -->
    <view class="floor_list">
      <!-- 楼层item项 -->
      <view class="floor_item" v-for="(item,i) in floorList" :key="i">
        <image class="floor_image" :src="item.floor_title.image_src" ></image>
        <!-- 楼层图片区域 -->
        <view class="floor_image_box">
          <!-- 左侧大图片 -->
          <navigator :url="item.product_list[0].url" class="left_box">
            <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
          </navigator>
          <!-- 右侧小图片 -->
          <view class="right_box">
            <navigator :url="item2.url" class="right_image_item" v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2 !== 0">
              <image :src="item2.image_src" :style="{width:item2.image_width + 'rpx'}" mode="widthFix"></image>
            </navigator>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import my_search from '../../components/my_search/my_search'
  import badgeMix from '../../mixins/mixins.js'
  export default {
    mixins:[badgeMix],
    data() {
      return {
        list:[],
        // 分类导航
        navList:[],
        // 楼层
        floorList:[]
      };
    },
    components: {
      'my-search':my_search
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      // 获取楼层数据
      this.floorListo()
    },
      
    methods: {
     async getSwiperList() {
       const {data:res} = await uni.$http.get('home/swiperdata')
       if(res.meta.status !== 200) {
         return uni.$showMsg()
       }
       this.list = res.message
      },
      async getNavList() {
       const {data:res} =  await uni.$http.get('home/catitems')
       if(res.meta.status !== 200) {
         return uni.$showMsg()
       }
       this.navList = res.message
      },
      navClickHanlder(item) {
        if(item.name === '分类') {
          uni.switchTab({
            url:'/pages/cate/cate'
          })
        }
      },
      // 获取楼层数据
      async floorListo() {
        const {data:res} = await uni.$http.get('home/floordata')
        if(res.meta.status !== 200) {
          return uni.$showMsg()
        }
        res.message.forEach(item => {
          item.product_list.forEach(item2 => {
            item2.url = '/subpackages/goods_list/goods_list?'+ item2.navigator_url.split('?')[1]
          })
        })
        this.floorList = res.message
      },
      gotoSearch() {
        uni.navigateTo({
          url:'/subpackages/search/search'
        })
      }
    }
  }
</script>

<style lang="scss">
.search {
  position: sticky;
  top: 0;
  z-index: 999;
}
swiper {
  height: 330rpx;
  .swiper-item,image {
    height: 100%;
    width: 100%;
    display: block;
  }
  
}
.nav-list {
  display: flex;
  justify-content: space-between;
  margin: 15px 0;
  .nav-item {
    image {
      width: 128rpx;
      height: 140rpx;
    }
  }
}
.floor_list {
  .floor_image {
    width: 100%;
    display: flex;
    height: 60rpx;
    
  }
  .floor_image_box {
    display: flex;
    padding-left: 10rpx;
    .right_box {
      flex: 1;
      display: flex;
      justify-content: space-around;
      flex-wrap: wrap;
      
    }
  }
}
</style>
